package com.gxa.p2p.controller;

import com.gxa.p2p.businessExceptionCode.ErrorCode;
import com.gxa.p2p.exception.BusinessException;
import com.gxa.p2p.pojo.AssetDetails;
import com.gxa.p2p.service.AssetDetailsService;
import com.gxa.p2p.util.MapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: cxy
 * Date: 2020/08/06 10:33
 * Description:
 * Version: V1.0
 */
@CrossOrigin
@Controller
@Transactional
@RequestMapping("/assetDetails")
@Api(value = "资产详情控制器", tags = "资产详情")
public class AssetDetailsController {
    @Resource
    AssetDetailsService assetDetailsService;

    /**
     * 通过用户id查询用户信息
     */
    @PostMapping
    @ResponseBody
    @ApiOperation(value = "查询用户资产详情的接口", notes = "通过用户编号获取该用户全部资产信息", response = Map.class, httpMethod = "GET")
    public Map<String, Object> getAssetDetails(@RequestBody AssetDetails assetDetails) {
                if (assetDetailsService.getAssetDetails(assetDetails) != null) {
                    MapUtil mapUtil = new MapUtil();
                    mapUtil.setCode("0");
                    mapUtil.setData(assetDetailsService.getAssetDetails(assetDetails));
                    mapUtil.setMsg("查询成功");
                    return mapUtil.getMap();
                } else {
                    throw new BusinessException(ErrorCode.FAILED);
        }
    }


}
